﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model.Util;
using Xproject.Framework.Utility.Extensions;
using Xproject.Framework.Core.Repositories;
using Xproject.Framework.Utility.ExceptionHandling;
using Xproject.Framework.Core;
using System.Linq.Expressions;
namespace Repository.Util
{
    public static class IdentityRep
    {
        public static Identity Get(this IRepositoryAsync<Identity> repository, string  guid)
        {
            Expression<Func<Identity, bool>> express = i => 1 == 1;           
            express = express.AndAlso(i => i.Guid == guid);            
            return repository.Query().Where(express).Select().OrderByDescending(i => i.CreateTime).FirstOrDefault();
        }

        public static Identity GetByUserId(this IRepositoryAsync<Identity> repository, string  userID)
        {
            Expression<Func<Identity, bool>> express = i => 1 == 1;
            if (!string.IsNullOrEmpty(userID))
            {
                express = express.AndAlso(i => i.ProjectID == userID);
            }
            return repository.Query().Where(express).Select().OrderByDescending(i => i.CreateTime).FirstOrDefault();
        }


    }
}
